package com.zxt.dlna.activity;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.os.Bundle;
import android.os.Handler;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.view.inputmethod.InputMethodManager;
import android.widget.FrameLayout;
import android.widget.RelativeLayout;

import com.zxt.dlna.R;


public class BaseActivity extends Activity
//		implements ClientConnector.ConnectLinstener
	{



	private View contentView;
	RelativeLayout rl_base;

	@SuppressLint("SourceLockedOrientationActivity")
	@Override
	protected void onCreate(Bundle bundle) {
		super.onCreate(bundle);
//		requestWindowFeature(Window.FEATURE_NO_TITLE);
//		getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);
//		BaseApplication.context = context;
//		ButterKnife.bind(this);

//		setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
//		setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);

//        DisplayMetrics metrics = new DisplayMetrics();
//        WindowManager wm = (WindowManager) getApplicationContext().getSystemService(Context.WINDOW_SERVICE);
//        wm.getDefaultDisplay().getMetrics(metrics);
//        density = metrics.density;
//        width = metrics.widthPixels;
//        height = metrics.heightPixels;

		setContentView(R.layout.activity_base);
//		rl_base = findViewById(R.id.rl_base);


//        AppManager.getAppManager().addActivity(this);
		// 修改状态栏颜色，4.4+生效
//		if (VERSION.SDK_INT >= VERSION_CODES.KITKAT) {
//			// 透明状态栏
//			getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
//			// 透明导航栏
//			getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
//		}

//		init_serial();

//		CustomDialog.Builder customBuilder = new CustomDialog.Builder(context);
//		customBuilder.setTitle("温馨提示").setMessage("请求连接，是否同意?")
//				.setNegativeButton("取消", new DialogInterface.OnClickListener() {
//					public void onClick(DialogInterface dialog, int which) {
//						dialog.cancel();
//
//					}
//				}).setPositiveButton("确认", new DialogInterface.OnClickListener() {
//			public void onClick(DialogInterface dialog, int which) {
//				dialog.cancel();
//
//				Log.e("bfa===showDialog", "===");
//
//				sendMessage("1","ok");
//			}
//		});
//		customDialog = customBuilder.create();



	}

	public void setContentLayout(int resId) {

		LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		contentView = inflater.inflate(resId, null);
		FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(FrameLayout.LayoutParams.FILL_PARENT, FrameLayout.LayoutParams.FILL_PARENT);
		contentView.setLayoutParams(layoutParams);
		contentView.setBackgroundDrawable(null);


//		if (null != ly_content) {
//			ly_content.addView(contentView);
//		}

	}

//	private void initData() {
////		mHandlerThread = new HandlerThread("MainActivity", android.os.Process.THREAD_PRIORITY_BACKGROUND);
////		mHandlerThread.start();
////		mHandler = new Handler(mHandlerThread.getLooper());
//		mConnector = new ClientConnector(mDstName, mDstPort);
//		mConnector.setOnConnectLinstener(this);
////        mData = new ArrayList<>();
////        mAdapter = new ArrayAdapter(this, R.layout.item, R.id.tv_text, mData);
////        mListView.setAdapter(mAdapter);
//
//		connectServer();
//	}
//
//	public void connectServer() {
//
//		mHandler.post(new ConnectRunnable());
//	}
//
//	private class ConnectRunnable implements Runnable {
//		@Override
//		public void run() {
//			try {
//				Log.e("ba===ConnectRunnable", mConnector+"===");
//
//				mConnector.connect();
//			} catch (Exception e) {
//				e.printStackTrace();
//			}
//		}
//	}
//
//	@Override
//	public void onReceiveData(final String data) {
//
//		Log.e("ba===onReceiveData", data+"===");
//
////		runOnUiThread(new Runnable() {
////			@Override
////			public void run() {
////				if (data.contains("request")) {
////					if ("s".equalsIgnoreCase(BaseApplication.type)) {
////
//////						showDialog(data.split("@")[0]);
////
////						Intent intent = new Intent("data.broadcast.action");
////						intent.putExtra("id", data.split("@")[0]);
////						context.sendBroadcast(intent);
////					}
////				} else if ("ok".equals(data)) {
////					if ("c".equalsIgnoreCase(BaseApplication.type)) {
////						Toast.makeText(context, "握手成功", Toast.LENGTH_SHORT).show();
////					}
////				} else {
////					new Thread() {
////						public void run() {
////							super.run();
////
//////                        5AA50883D1E0000000D43A
//////                        write(hexStringToBytes("5AA50883D1E0000000D43A"));
////
//////                                uartJnit.getInstance().sendCmds("5AA50883D1E0000000D43A");
////
////							boolean isSendy = uartJnit.getInstance().sendCmds(data);
////
////							Log.e("device_id===1", isSendy+"====");
////
////
////						}
////					}.start();
////				}
////			}
////		});
//
////		m_myHandler.post(new Runnable() {
////			@Override
////			public void run() {
////				if(data.contains("request")){
////					if("s".equalsIgnoreCase(BaseApplication.type)){
////
////						showDialog(data.split("@")[0]);
////					}
////				}else if("ok".equals(data)){
////					if("c".equalsIgnoreCase(BaseApplication.type)){
////						Toast.makeText(context, "握手成功", Toast.LENGTH_SHORT).show();
////					}
////				}
////			}
////		});
//
//	}



//	/* 打开串口 */
//	private void init_serial() {
//		try {
//			serialttyS1 = new SerialPort(new File("/dev/ttyS1"),115200,0);
//			ttyS1InputStream = serialttyS1.getInputStream();
//			ttyS1OutputStream = serialttyS1.getOutputStream();
//
//		} catch (Exception e) {
//			e.printStackTrace();
//		}
//	}
//
//	public void write(byte[] bytes){
//		/* 串口发送字节 */
//		try {
//			ttyS1OutputStream.write(bytes);   //TODO
//		} catch (Exception e) {
//			e.printStackTrace();
//		}
//	}
//
//	public void read(byte[] bytes){
//		/* 串口发送字节 */
//		try {
//			int temp = ttyS1InputStream.read(bytes);   //TODO
////			tv_temp.setText(temp+"℃");
//		} catch (Exception e) {
//			e.printStackTrace();
//		}
//	}



	
	@Override
	protected void onResume() {
		super.onResume();
	}

	@Override
	protected void onDestroy() {
		super.onDestroy();
	}

	@Override
	public boolean onTouchEvent(MotionEvent event) {
		if (event.getAction() == MotionEvent.ACTION_DOWN) {
			try {
				InputMethodManager imm = (InputMethodManager) getSystemService(INPUT_METHOD_SERVICE);
				return imm.hideSoftInputFromWindow(getCurrentFocus().getWindowToken(), 0);
			} catch (Exception e) {
			}
		}
		return super.onTouchEvent(event);
	}

	public void gotoAct(Class<?> clazz) {
		Intent intent = new Intent(this, clazz);
		startActivity(intent);
	}



}
